﻿using Avalonia.Data.Converters;
using Avalonia.Styling;
using System;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Reactive;

namespace AutojsController.Helpers
{
    public static class Converter
    {
        public static ThemeVariant StringToTheme(string themeString)
        {
            return themeString.ToLower() switch
            {
                "dark" => ThemeVariant.Dark,
                "light" => ThemeVariant.Light,
                _ => ThemeVariant.Light // Default to Light if the string doesn't match
            };
        }

        public static string ThemeToString(ThemeVariant theme)
        {
            if (theme == ThemeVariant.Dark)
                return "dark";
            if (theme == ThemeVariant.Light)
                return "light";
            return "light"; // Default to Light if the theme doesn't match
        }

        public static uint IPAddressToUint(IPAddress ip)
        {
            return BitConverter.ToUInt32(ip.GetAddressBytes().Reverse().ToArray(), 0);
        }

        public static IPAddress UintToIPAddress(uint ipUint)
        {
            return new IPAddress(BitConverter.GetBytes(ipUint).Reverse().ToArray());
        }
    }

    public class SelectedBackgroundConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (value is bool b && b) ? "LightBlue" : "Transparent";
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
    }
}
